package com.henanuniversity.service.impl;

import com.henanuniversity.dao.CartDao;
import com.henanuniversity.dao.impl.CartDaoImpl;
import com.henanuniversity.po.Cart;
import com.henanuniversity.service.CartService;
import com.henanuniversity.utils.DBUtils;

import java.util.ArrayList;
import java.util.List;

public class CartServiceImpl implements CartService {
    @Override
    public List<Cart> listCart(Cart cart) {
        List<Cart> list = new ArrayList<>();
        CartDaoImpl dao = new CartDaoImpl();
        list = dao.listCart(cart);
        DBUtils.close();
        return list;
    }

    @Override
    public int saveCart(Cart cart) {
        int result=0;
        try {
            CartDao dao=new CartDaoImpl();
            result=dao.saveCart(cart);
        } catch (Exception e) {
            e.printStackTrace();
        }
        DBUtils.close();
        return result;
    }

    @Override
    public int removeCart(Cart cart) {
        int result=0;
        CartDao dao=new CartDaoImpl();
        result=dao.removeCart(cart);
        DBUtils.close();
        return result;
    }

    @Override
    public int updateCart(Cart cart) {
        int result=0;
        CartDao dao=new CartDaoImpl();
        result=dao.updateCart(cart);
        DBUtils.close();
        return result;
    }
}
